﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnLogin_ServerClick(object sender, EventArgs e)
    {
        if (username.Value.Equals(""))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "$('#username').poshytip({ content: '用户名不能为空', hideTimeout: 1, alignTo: 'target', alignX: 'left',alignY:'center', offsetX: 0, offsetY: 5 }).poshytip('show');", true);
        }
        else if (password.Value.Equals(""))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "$('#password').poshytip({ content: '密码不能为空', hideTimeout: 1, alignTo: 'target', alignX: 'left',alignY:'center', offsetX: 0, offsetY: 5 }).poshytip('show');", true);
        }
        else  if (UserManager.Login(username.Value, password.Value))
        {
            User u = UserManager.FindByLoginName(username.Value);
            //Session.Timeout = 1440;
            Session["user"] = u;
            if (OnlineList.getOnlineUsers()[u.LoginName] == null)
                OnlineList.getOnlineUsers().Add(u.LoginName, u.UserName);
            FormsAuthentication.RedirectFromLoginPage(u.LoginName, false);
            Response.Redirect("Main.aspx");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "$('#username').poshytip({ content: '用户名或密码错误，请重新输入!', hideTimeout: 1, alignTo: 'target', alignX: 'inner',alignY:'center', offsetX: 0, offsetY: 5 }).poshytip('show');", true);
        }
    }
}
